<?php
/***
//自我游订单确认通知
***/

if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}
logfile(json_encode($_REQUEST),'zwy_ordertrue_data');

$order_id = $_REQUEST['order_id'];
$ticket_num = $_REQUEST['ticket_num'];

if($order_id){
	$sel = "select * from all_api_order where apiOrder='$order_id' limit 1";
	$GLOBALS['le']->query($sel);
	if($GLOBALS['le']->fetch_assoc()){
		$response = <<<xml
			<root>
				<result>true</result>
				<msg>接收成功</msg>
			</root>
xml;
		echo $response;
		exit;
	}
	else{
		$response = <<<xml
			<root>
				<result>false</result>
				<msg>无此订单</msg>
			</root>
xml;
		echo $response;
		exit;
	}
}
else{
	$response = <<<xml
			<root>
				<result>false</result>
				<msg>请输入有效数据</msg>
			</root>
xml;
	echo $response;
	exit;
}

function logfile($word,$path){
	$filepath= '/var/www/html/new/d/logs/api/ZiWoYou/'.$path.'.txt';
	if(file_exists($filepath)){
		$word = date("Y-m-d H:i:s")."|".$word;
		// $word = mb_convert_encoding($word, 'GBK', 'UTF-8');
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
		{
			rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
			$handler=fopen($filepath,'w');
			flock($handler, LOCK_EX) ;
			fwrite($handler,"\n".$word);
			flock($handler, LOCK_UN);
			fclose($handler);
		}
		else
		{
			$fp = fopen('/var/www/html/new/d/logs/api/ZiWoYou/'.$path.'.txt',"a");
			flock($fp, LOCK_EX);
			fwrite($fp,$word."\n");
			flock($fp, LOCK_UN);
			fclose($fp);
		}
	}else{
		$fp = fopen('/var/www/html/new/d/logs/api/ZiWoYou/'.$path.'.txt',"a");
		flock($fp, LOCK_EX);
		fwrite($fp,date('Y-m-d H:i:s')."|".$word."\n");
		flock($fp, LOCK_UN);
		fclose($fp);
	}
}
?>